qui {
	capture program drop ccn_beta_delta_het_newsym
	local count=0
	local subsample = "$subsample"
	local modelname = "$modelname"
	foreach lhs in $LHSlist { 
		local controls="${CONTROLlist_`lhs'}"
		local beta_controls "${BETA_control_list}"
		local delta_controls "${DELTA_control_list}"
		foreach rhs in $RHSlist { 
			foreach robust in $robust_list {
				forvalues K=$K_list {
					noisily display "LHS=`lhs', RHS=`rhs', SE=`robust', K=`K', $S_DATE, $S_TIME"
					qui {
						local count=`count'+1
						matrix actual_estimates_mat = J($boot_reps,28,-9)
						mat colnames actual_estimates_mat = const_hettobit beta1_hettobit beta2_hettobit beta3_hettobit d_const_hettobit d_delta1_hettobit ///
							const_symm beta1_symm beta2_symm beta3_symm d_const_symm d_delta1_symm ///		
							const_hetuni beta1_hetuni beta2_hetuni beta3_hetuni d_const_hetuni d_delta1_hetuni ///
							const_none beta1_none beta2_none beta3_none ///
							const_naive beta1_naive beta2_naive beta3_naive ///
							K iteration
						use "$datapath/003_cluster_`subsample'_`lhs'.dta", clear
						local control_length = 0
						foreach control of varlist `controls' {
							local control_length = `control_length' + 1
						}
						global control_length = `control_length'
						qui tab X_`K', generate(dumX_`K'_)
						tempfile temp
						save `temp', replace
						local rowcounter = 1
						forvalues i=1(1)$boot_reps {
							noisily display "Iteration `i', $S_DATE, $S_TIME"
							use "`temp'", clear
							bsample 

							*Het Tobit
							qui ccn_beta_delta_het_newsym het_tobit `K' `rhs' `lhs' `robust' "`controls'" het_tobit 1 "`beta_controls'" "`delta_controls'" 0
							matrix actual_estimates_mat[`rowcounter',1] = COEFFS[1,3] // constant
							matrix actual_estimates_mat[`rowcounter',2] = COEFFS[1,4] // hours
							matrix actual_estimates_mat[`rowcounter',3] = COEFFS[1,5] // afqt
							matrix actual_estimates_mat[`rowcounter',4] = COEFFS[1,6] // hrsafqt
							matrix actual_estimates_mat[`rowcounter',5] = COEFFS[1,1] // Delt constant
							matrix actual_estimates_mat[`rowcounter',6] = COEFFS[1,2] // Delt interaction

							*Symmetric
							qui ccn_beta_delta_het_newsym symmetric `K' `rhs' `lhs' `robust' "`controls'" het_tobit 1 "`beta_controls'" "`delta_controls'" 0
							matrix actual_estimates_mat[`rowcounter',7] = COEFFS[1,3] // constant
							matrix actual_estimates_mat[`rowcounter',8] = COEFFS[1,4] // hours
							matrix actual_estimates_mat[`rowcounter',9] = COEFFS[1,5] // afqt
							matrix actual_estimates_mat[`rowcounter',10] = COEFFS[1,6] // hrsafqt
							matrix actual_estimates_mat[`rowcounter',11] = COEFFS[1,1] // Delt constant
							matrix actual_estimates_mat[`rowcounter',12] = COEFFS[1,2] // Delt interaction


							*Het Uniform
							qui ccn_beta_delta_het_newsym het_uniform `K' `rhs' `lhs' `robust' "`controls'" het_tobit 1 "`beta_controls'" "`delta_controls'" 0
							matrix actual_estimates_mat[`rowcounter',13] = COEFFS[1,3] // constant
							matrix actual_estimates_mat[`rowcounter',14] = COEFFS[1,4] // hours
							matrix actual_estimates_mat[`rowcounter',15] = COEFFS[1,5] // afqt
							matrix actual_estimates_mat[`rowcounter',16] = COEFFS[1,6] // hrsafqt
							matrix actual_estimates_mat[`rowcounter',17] = COEFFS[1,1] // Delt constant
							matrix actual_estimates_mat[`rowcounter',18] = COEFFS[1,2] // Delt interaction

							*No Controls
							qui ccn_beta_delta_het_newsym naiveN `K' `rhs' `lhs' `robust' "`controls'" het_tobit 1 "`beta_controls'" "`delta_controls'" 0
							matrix actual_estimates_mat[`rowcounter',19] = COEFFS[1,1] // constant
							matrix actual_estimates_mat[`rowcounter',20] = COEFFS[1,2] // hours
							matrix actual_estimates_mat[`rowcounter',21] = COEFFS[1,3] // afqt
							matrix actual_estimates_mat[`rowcounter',22] = COEFFS[1,4] // hrsafqt

							*Naive
							qui ccn_beta_delta_het_newsym naive `K' `rhs' `lhs' `robust' "`controls'" het_tobit 1 "`beta_controls'" "`delta_controls'" 0
							matrix actual_estimates_mat[`rowcounter',23] = COEFFS[1,1] // constant
							matrix actual_estimates_mat[`rowcounter',24] = COEFFS[1,2] // hours
							matrix actual_estimates_mat[`rowcounter',25] = COEFFS[1,3] // afqt
							matrix actual_estimates_mat[`rowcounter',26] = COEFFS[1,4] // hrsafqt

							matrix actual_estimates_mat[`rowcounter',27] = `K'
							matrix actual_estimates_mat[`rowcounter',28] = `i'

							local rowcounter = `rowcounter'+1
						}
						clear
						qui svmat actual_estimates_mat, names(col)

						collapse const_hettobit beta1_hettobit beta2_hettobit beta3_hettobit d_const_hettobit d_delta1_hettobit ///
							const_symm beta1_symm beta2_symm beta3_symm d_const_symm d_delta1_symm ///		
							const_hetuni beta1_hetuni beta2_hetuni beta3_hetuni d_const_hetuni d_delta1_hetuni ///
							const_none beta1_none beta2_none beta3_none ///
							const_naive beta1_naive beta2_naive beta3_naive K ///
							(sd) sd_const_hettobit = const_hettobit sd_beta1_hettobit = beta1_hettobit sd_beta2_hettobit = beta2_hettobit sd_beta3_hettobit = beta3_hettobit sd_d_const_hettobit = d_const_hettobit sd_d_delta1_hettobit = d_delta1_hettobit ///
							sd_const_symm = const_symm sd_beta1_symm = beta1_symm sd_beta2_symm = beta2_symm sd_beta3_symm = beta3_symm sd_d_const_symm = d_const_symm sd_d_delta1_symm = d_delta1_symm ///
							sd_const_hetuni = const_hetuni sd_beta1_hetuni = beta1_hetuni sd_beta2_hetuni = beta2_hetuni sd_beta3_hetuni = beta3_hetuni sd_d_const_hetuni = d_const_hetuni sd_d_delta1_hetuni = d_delta1_hetuni ///
							sd_const_none = const_none sd_beta1_none = beta1_none sd_beta2_none = beta2_none sd_beta3_none = beta3_none ///
							sd_const_naive = const_naive sd_beta1_naive = beta1_naive sd_beta2_naive = beta2_naive sd_beta3_naive = beta3_naive ///
							(count) Niter=const_symm
							
						keep const_symm beta1_symm beta2_symm beta3_symm d_*_symm const_hettobit beta1_hettobit beta2_hettobit beta3_hettobit d_*_hettobit const_hetuni beta1_hetuni beta2_hetuni beta3_hetuni d_*_hetuni sd_* const_naive* beta1_naive* beta2_naive* beta3_naive* const_none* beta1_naive* beta2_none* beta3_none*  Niter N 
						gen LHS="`lhs'"
						gen RHS="`rhs'"
						gen Kcluster=`K'
						gen Robust="`robust'"
						save "$datapath/004_het_beta3_delta1_results_`subsample'_`modelname'_`lhs'_`robust'_K`K'BOOT.dta", replace
					}
				}		
			}
		}
	}
}
